package model.cardData;

import java.util.ArrayList;

public class CardSet { //TODO: abstract?
	
	protected ArrayList<Card> cards;
	private CardVisibility visible;
	
	public CardSet(CardVisibility cv) {
		this.visible = cv;
		cards = new ArrayList<Card>();
	}

	public CardVisibility getVisible() {
		return visible;
	}
	
	public Card getCard(int index) {
		//TODO
		return null;
	}
	
	public Card getCard(CardValue cv, CardSuit cs) {
		//TODO
		return null;
	}
	
	//TODO: entfernen
	protected boolean containsCard(CardValue cv, CardSuit cs) {
		for(Card c : cards) {
			if(c.getCardValue().equals(cv) && c.getCardSuit().equals(cs)) {
				return true;
			}
		}
		return false;
	}
	
	/**
	 * Gibt die Anzahl der Karten in der Menge zurück, die den Wert cv haben.
	 * z.B. Anzahl Vieren
	 */
	public int numCards(CardValue cv) throws Exception {
		
		if(visible==CardVisibility.NONE || visible==CardVisibility.TOP){
			throw new Exception("exception: cards not visible!");
		}
		
		int i = 0;
		for(Card c : cards) {
			if(c.getCardValue().equals(cv)) {
				i++;
			}
		}
		return i;
	}
	
	public int numCards() {
		return cards.size();
	}
	

	public void addCard(Card c) {
		cards.add(c);
	}
	
	public boolean isEmpty() {
		return cards.isEmpty();
	}
	
	public void remove(CardValue cv, CardSuit cs) {
		for(Card x : cards) {
			if(x.getCardValue().equals(cv) && x.getCardSuit().equals(cs)) {
				cards.remove(x);
				break;
			}
		}
	}
}
